<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=tis-620" />
<title>Service Check</title>
<script type="text/javascript" src="ajax.js"></script>
<!--<script type="text/JavaScript">
function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}
onload="JavaScript:timedRefresh(10000);"
</script>
-->
</head>
<body >
<form name="form1" method="post" action="" >
<div style="padding-left:50px;padding-top:40px;">
<p style="padding-left:12px;padding-top:8px;"><button type="submit">Ping</button></p>
<table width="1000" style="border: 1px #cccccc solid;" cellpadding="5">  
    <tr bgcolor="#cccccc">   
    <th> Service </th>
    <th> Monitor </th>
    <th> Network/IP </th>
    <th> ResponseTime(ms)</th>
    <th> SMS </th>
    <th> Check Service</th>
  </tr>
<?php 
	include_once 'monitor.php'; 	
	include_once 'net_ping.php'; 
	
	$xml = simplexml_load_file("service_list.xml");
	$i=0;
	
	$doc = new DOMDocument();
  	$doc->formatOutput = true;
  
 	$r = $doc->createElement( "service" );
 	$doc->appendChild( $r );
 	
	foreach($xml->web as $child){
	
	$bg="#eeeeee";
	if($i%2==0)
	{$bg="#ffffff";}
	
 	echo "<tr bgcolor=".$bg." align=\"center\" id=".($i+1).">";	
	echo "<td>".$child->number." </td>";
	$ip=$child->monitor;
	echo "<td><a href=\"".$child->url."\">".$ip."</a></td>";
	echo "<td>";
	$hip=gethostbyname($ip);
	if($hip==$ip)
	{ echo "Cannot Connect";}
	else
	{ echo $hip;}
	echo "</td>";
	echo "<td>";
	$ping = new Net_Ping; 
	$ping->ping($ip); 

	if ($ping->time) 
  		echo "Time: ".$res=(($ping->time)*1000); 
	else 
 		echo $ping->errstr; ;
	echo "</td>";
	echo "<td>";
	$sms=$child->sms;
	if($sms=="yes")
	{
		echo '<input name="sms'.($i+1).'" type="checkbox" checked="checked">';
	}
	else if($sms=="no")
	{
		echo '<input name="sms'.($i+1).'" type="checkbox">';
	}
	echo "<td>";
	$check = monitor($ip , 80);
	echo "<a href=\"".$child->url."\">".$check ."</a>";
	echo "</td>";
	echo "</tr>";
	$i++;
	
	$service= array();
  	$service [] = array(
  	'number' => $i,
  	'monitor' => $ip,
  	'ip' => $hip,
  	'response' => $res,
  	'sms' => '',
  	'checkservice' => $check
  );

  
  foreach( $service as $web )
  {
  $b = $doc->createElement( "web" );
  
  $number= $doc->createElement( "number" );
  $number->appendChild(
  $doc->createTextNode( $web ['number'] )
  );
  $b->appendChild( $number );
  
  $monitor = $doc->createElement( "monitor" );
  $monitor->appendChild(
  $doc->createTextNode( $web ['monitor'] )
  );
  $b->appendChild( $monitor );
  
  $ip = $doc->createElement( "ip" );
  $ip->appendChild(
  $doc->createTextNode( $web ['ip'] )
  );
  $b->appendChild( $ip );
  
  $response = $doc->createElement( "response" );
  $response->appendChild(
  $doc->createTextNode( $web ['response'] )
  );
  $b->appendChild( $response  );
  
  $sms = $doc->createElement( "sms" );
  $sms->appendChild(
  $doc->createTextNode( $web ['sms'] )
  );
  $b->appendChild( $sms  );
  
  $checkservice = $doc->createElement( "checkservice" );
  $checkservice->appendChild(
  $doc->createTextNode( $web ['checkservice'] )
  );
  $b->appendChild($checkservice);
  
  $r->appendChild( $b );
  }
  }
 ?> 
</table>
</div>	
</form>
<?php  
	//$time=mktime();
	//$time = floor($time/60);
  	//$savelog = "serveice-logs".$time.".xml";
  	$savelog = "serveice-logs.xml";
  	$doc->save($savelog)
?>
</body>
</html>